package com.itrh.auth.controller;

import com.itrh.auth.service.IMenuService;
import com.itrh.auth.domain.Menu;
import com.itrh.auth.query.MenuQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.itrh.org.util.Result;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Resource
    public IMenuService menuService;



    @PutMapping
    public Result addOrUpdate(@RequestBody Menu menu){
        System.out.println(menu);
        return menuService.saveOrUpdate(menu);
    }

    @DeleteMapping(value="/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return menuService.deleteById(id);
    }
	
    //获取用户
    @GetMapping("/{id}")
    public Result get(@PathVariable("id")Long id) {
        return menuService.selectById(id);
    }

    @GetMapping
    public Result list() {
        return menuService.selectAll();
    }

    @PostMapping
    public Result pageList(@RequestBody MenuQuery query) {
        return menuService.pageList(query);
    }

    @PatchMapping
    public Result batchRemove(@RequestBody List<Long> ids){
        return menuService.batchRemove(ids);
    }

    @GetMapping("/tree")
    public Result getTree() {
        return menuService.getTree();
    }


}
